<html>
<head><meta charset="utf-8"><title>mem::size_of: do not error if layout computations fail · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html">mem::size_of: do not error if layout computations fail</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="217115253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217115253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217115253">(Nov 18 2020 at 10:02)</a>:</h4>
<p><code>std::mem::size_of</code> currently emits a compilation error if the layout computation failed. For example:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">"{}"</span><span class="p">,</span><span class="w"> </span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">size_of</span>::<span class="o">&lt;</span><span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="kt">usize</span>::<span class="n">MAX</span><span class="p">]</span><span class="o">&gt;</span><span class="p">());</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>causes</p>
<div class="codehilite"><pre><span></span><code>error[E0080]: the type `[u8; 18446744073709551615]` is too big for the current architecture

error[E0080]: evaluation of constant expression failed
 --&gt; src/main.rs:2:20
  |
2 |     println!(&quot;{}&quot;, std::mem::size_of::&lt;[u8; usize::MAX]&gt;());
  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors

error: erroneous constant used
 --&gt; src/main.rs:2:20
  |
2 |     println!(&quot;{}&quot;, std::mem::size_of::&lt;[u8; usize::MAX]&gt;());
  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
  |
  = note: `#[deny(const_err)]` on by default
</code></pre></div>



<a name="217115268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217115268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217115268">(Nov 18 2020 at 10:02)</a>:</h4>
<p>there are two issues here imo:</p>



<a name="217115715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217115715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217115715">(Nov 18 2020 at 10:07)</a>:</h4>
<ul>
<li>the type <code>[u8; usize::MAX]</code> is <strong>not</strong> too big for the current architecture, for example:</li>
</ul>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(min_const_generics)]</span><span class="w"></span>

<span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Assoc</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span>: <span class="o">'</span><span class="nb">static</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">[</span><span class="n">T</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="p">]</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Assoc</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;'</span><span class="nb">static</span><span class="w"> </span><span class="p">[</span><span class="n">T</span><span class="p">];</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="w"></span>
<span class="w">        </span><span class="s">"{}"</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">size_of</span>::<span class="o">&lt;&lt;</span><span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="kt">usize</span>::<span class="n">MAX</span><span class="p">]</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">Foo</span><span class="o">&gt;</span>::<span class="n">Assoc</span><span class="o">&gt;</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>compiles and prints the expected size</p>



<a name="217115839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217115839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217115839">(Nov 18 2020 at 10:08)</a>:</h4>
<p>am changing this error message in <a href="https://github.com/rust-lang/rust/issues/79158">#79158</a> to "values of the type <code>...</code> are too big"</p>



<a name="217115981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217115981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217115981">(Nov 18 2020 at 10:10)</a>:</h4>
<ul>
<li>IMO <code>size_of</code> really should not cause a compilation error here,</li>
</ul>



<a name="217116170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217116170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217116170">(Nov 18 2020 at 10:13)</a>:</h4>
<p>but instead work similar to <code>let _x = 1/0</code>, emitting a <code>unconditional_panic</code> lint</p>



<a name="217116215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217116215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217116215">(Nov 18 2020 at 10:13)</a>:</h4>
<p>as <code>size_of</code> never actually deals with a value of type <code>T</code></p>



<a name="217116481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217116481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217116481">(Nov 18 2020 at 10:16)</a>:</h4>
<p>i can't really explain myself too well but causing an error here just <em>feels wrong</em>™</p>



<a name="217116496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217116496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217116496">(Nov 18 2020 at 10:16)</a>:</h4>
<p>There is no way to construct a value of that type.</p>



<a name="217116508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217116508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217116508">(Nov 18 2020 at 10:17)</a>:</h4>
<p>yeah, but we don't have to do that for <code>size_of</code></p>



<a name="217116520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217116520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217116520">(Nov 18 2020 at 10:17)</a>:</h4>
<p>we can still use the type for trait bounds and projections</p>



<a name="217116604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217116604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217116604">(Nov 18 2020 at 10:18)</a>:</h4>
<p><code>size_of</code> reads from the layout of the type. To fix this, you would have to duplicate all layout logic just for <code>size_of</code>, or you would have to insert error code at every use of <code>layout_of</code> that doesn't involve <code>size_of</code>.</p>



<a name="217116664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217116664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217116664">(Nov 18 2020 at 10:19)</a>:</h4>
<p><code>layout_of</code> already returns <code>Result&lt;.., LayoutError&gt;</code></p>



<a name="217116719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217116719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217116719">(Nov 18 2020 at 10:20)</a>:</h4>
<p>so instead of<code>size_of</code> emitting the err as a compilation error it contains it in it's panic message</p>



<a name="217116730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217116730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217116730">(Nov 18 2020 at 10:20)</a>:</h4>
<p>that's not really a lot of duplication, is it?</p>



<a name="217116811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217116811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217116811">(Nov 18 2020 at 10:21)</a>:</h4>
<p>Forgot how it worked.</p>



<a name="217116915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217116915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217116915">(Nov 18 2020 at 10:22)</a>:</h4>
<p>no worries <span aria-label="heart" class="emoji emoji-2764" role="img" title="heart">:heart:</span></p>



<a name="217116945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217116945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217116945">(Nov 18 2020 at 10:23)</a>:</h4>
<p>If it were changed to a panic message, that would still cause an error during codegen of <code>size_of</code> as <code>size_of</code> in cg_llvm invokes the const eval implementation of this and several other intrinsics.</p>



<a name="217116986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217116986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217116986">(Nov 18 2020 at 10:23)</a>:</h4>
<p>I want to codegen <code>size_of</code> into a panic</p>



<a name="217116996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217116996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217116996">(Nov 18 2020 at 10:23)</a>:</h4>
<p>if it fails, instead of into an error</p>



<a name="217117068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217117068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217117068">(Nov 18 2020 at 10:24)</a>:</h4>
<p>so </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">size_of</span>::<span class="o">&lt;</span><span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="kt">usize</span>::<span class="n">MAX</span><span class="p">]</span><span class="o">&gt;</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="217117149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217117149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217117149">(Nov 18 2020 at 10:25)</a>:</h4>
<p>would instead be more similar to</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">size_of_concrete_ty</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">panic</span><span class="o">!</span><span class="p">(</span><span class="s">"values of the type `[u8; 18446744073709551615]` are too big for the current architecture"</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">   </span><span class="n">size_of_concrete_ty</span><span class="p">(();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="217117231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217117231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217117231">(Nov 18 2020 at 10:26)</a>:</h4>
<p>What would the advantage of that be?</p>



<a name="217117397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217117397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217117397">(Nov 18 2020 at 10:28)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217116481">said</a>:</p>
<blockquote>
<p>i can't really explain myself too well but causing an error here just <em>feels wrong</em>™</p>
</blockquote>



<a name="217117470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217117470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217117470">(Nov 18 2020 at 10:29)</a>:</h4>
<p>i can try to explain myself a bit better here, the size of values of a type is not related to the well-formedness of said type</p>



<a name="217117495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217117495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217117495">(Nov 18 2020 at 10:29)</a>:</h4>
<p>which is why <code>[u16; usize::MAX]</code> can be used in projections and stuff</p>



<a name="217118021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217118021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217118021">(Nov 18 2020 at 10:34)</a>:</h4>
<p>i think <code>size_of</code> causing a compilation error also causes subtle misunderstandings like <a href="https://github.com/rust-lang/rust/pull/79135#issuecomment-729361380">https://github.com/rust-lang/rust/pull/79135#issuecomment-729361380</a></p>
<blockquote>
<p>[When dealing with <code>[[u8; M]; N]</code>, ] It is obvious that using N = M = usize::MAX will result in invalid types (in the sense as discussed in the linked issue)</p>
</blockquote>



<a name="217119264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217119264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217119264">(Nov 18 2020 at 10:48)</a>:</h4>
<p>i feel like <code>size_of</code> is also another "unnecessary" way to cause "type" errors post typeck, which should ideally be avoided because it causes really unhelpful errors</p>



<a name="217119287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217119287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217119287">(Nov 18 2020 at 10:48)</a>:</h4>
<p>To me <code>size_of</code> feels like a generic constant more than something that happens at runtime. Emitting a panic for that is a little bit like how promotion handles panics. There's an assertion before getting to the uncomputable promoted constant, so we never reach the invalid code. Basically this would make a <code>size_of::&lt;T&gt;()</code> invocation <code>{assert!(well_formed_for_value&lt;T&gt;()); actual_size_of&lt;T&gt;()}</code>. But in contrast to promotion, right now <code>size_of</code> is something that is known to happen at compile time, so it's like a constant, thus we emit a compile-time error if we fail to evaluate it. So basically any use of <code>size_of::&lt;T&gt;()</code> technically requires a <code>where const size_of::&lt;T&gt;()</code> bound on all functions using <code>size_of::&lt;T&gt;()</code> without a concrete <code>T</code>. Now this would be very invasive, so we could autogenerate such bounds <em>just</em> for the <code>size_of</code> case. Though I have been informed that this may not actually be feasible. With such autogenerated bounds, we'd get better errors again</p>



<a name="217119323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217119323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217119323">(Nov 18 2020 at 10:49)</a>:</h4>
<p>in general I mostly feel like <code>size_of</code> has <em>no right</em> to cause a compilation error. These are just my expectations of how things should work so it probably isn't really helpful to people who have different expectations here.</p>



<a name="217119368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217119368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217119368">(Nov 18 2020 at 10:49)</a>:</h4>
<p>if <code>size_of</code> were a constant on <code>Sized</code>, then it not being computable would reasonably cause a compile-time error</p>



<a name="217119431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217119431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217119431">(Nov 18 2020 at 10:50)</a>:</h4>
<p>and there definitely was some discussion about something like that, although I can't find it right now</p>



<a name="217119650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217119650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217119650">(Nov 18 2020 at 10:52)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217119368">said</a>:</p>
<blockquote>
<p>if <code>size_of</code> were a constant on <code>Sized</code>, then it not being computable would reasonably cause a compile-time error</p>
</blockquote>
<p>yeah, though that also brings some other issues with it <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="217119672"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217119672" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217119672">(Nov 18 2020 at 10:53)</a>:</h4>
<p>if we ever want to require associated consts to be wf</p>



<a name="217120190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217120190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217120190">(Nov 18 2020 at 10:59)</a>:</h4>
<p>(tbh I would personally be fine with completely scrapping the compilation error on <code>SizeOverflow</code> and instead emit a deny by default lint and just panic everywhere such a type is used at runtime, though that's probably even more controversial <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span> )</p>



<a name="217120254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217120254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217120254">(Nov 18 2020 at 11:00)</a>:</h4>
<p>that still won't improve the diagnostic ^^</p>



<a name="217120289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217120289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217120289">(Nov 18 2020 at 11:00)</a>:</h4>
<p>(though you can then just run your program and look at the stack trace, not ideal.</p>



<a name="217120484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217120484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217120484">(Nov 18 2020 at 11:02)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217120254">said</a>:</p>
<blockquote>
<p>that still won't improve the diagnostic ^^</p>
</blockquote>
<p>well, you can at least point at the mir local that caused that lint</p>



<a name="217120497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217120497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217120497">(Nov 18 2020 at 11:02)</a>:</h4>
<p>you can also do that with an error though</p>



<a name="217120564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217120564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217120564">(Nov 18 2020 at 11:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217120190">said</a>:</p>
<blockquote>
<p>(tbh I would personally be fine with completely scrapping the compilation error on <code>SizeOverflow</code> and instead emit a deny by default lint and just panic everywhere such a type is used at runtime, though that's probably even more controversial <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span> )</p>
</blockquote>
<p>that's just idealism speaking here, so there isn't really a point in doing so except that it's "cleaner" (whatever that means)</p>



<a name="217121049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217121049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217121049">(Nov 18 2020 at 11:08)</a>:</h4>
<p>The problem with an error or lint is that they get reported in other crates, so for lints we wouldn't see them at all and for errors we don't have a span to report them on. If this is 5 function calls deep, you have to figure out which concrete type used as input caused it</p>



<a name="217121085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217121085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217121085">(Nov 18 2020 at 11:09)</a>:</h4>
<p>we technically have this information available via the query stack, but we can't use it for diagnostics and it's not reliable</p>



<a name="217121139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217121139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217121139">(Nov 18 2020 at 11:09)</a>:</h4>
<p>yeah <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span> there is a reason why we implement const wf using explicit where bounds</p>



<a name="217121216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217121216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217121216">(Nov 18 2020 at 11:10)</a>:</h4>
<p>we might at least add a short note saying in which instance we currently are</p>



<a name="217121286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217121286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217121286">(Nov 18 2020 at 11:11)</a>:</h4>
<p>so something like "in a concrete of <code>fn whatever</code> called with the generic parameters <code>u32, 17usize, String</code>"</p>



<a name="217122097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217122097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217122097">(Nov 18 2020 at 11:22)</a>:</h4>
<p>I just worry that without a backtrace this will just report the <code>std::mem::size_of</code> wrapper funciton <span aria-label="wink" class="emoji emoji-1f609" role="img" title="wink">:wink:</span></p>



<a name="217122159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217122159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217122159">(Nov 18 2020 at 11:22)</a>:</h4>
<p>aaah, that's true</p>



<a name="217122259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217122259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217122259">(Nov 18 2020 at 11:23)</a>:</h4>
<p>maybe once the mir inliner is running by default <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="217126273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217126273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217126273">(Nov 18 2020 at 12:11)</a>:</h4>
<p>re changing size overflows to an runtime error, would that mean that the following transformation becomes unsound?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">before</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">x</span>: <span class="kt">u8</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">match</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="mi">0</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="nc">T</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">?</span><span class="w"></span>
<span class="w">        </span><span class="mi">1</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="n">y</span>: <span class="nc">T</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">?</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">whatever</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">after</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">x</span>: <span class="kt">u8</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_idk</span>: <span class="nc">T</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">?</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">match</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="mi">0</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">(),</span><span class="w"></span>
<span class="w">        </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">whatever</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>where <code>?</code> is free of sideeffects, e.g. array initialization</p>



<a name="217126335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217126335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217126335">(Nov 18 2020 at 12:11)</a>:</h4>
<p>because we change the behavior for <code>x &gt; 1</code>... that seems undesirable to me, so maybe it's not worth it in the end <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="217500315"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217500315" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217500315">(Nov 21 2020 at 12:42)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217116170">said</a>:</p>
<blockquote>
<p>but instead work similar to <code>let _x = 1/0</code>, emitting a <code>unconditional_panic</code> lint</p>
</blockquote>
<p><code>size_of</code> currently cannot panic, and there might be code which relies on that...</p>



<a name="217500333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217500333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217500333">(Nov 21 2020 at 12:43)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217117470">said</a>:</p>
<blockquote>
<p>i can try to explain myself a bit better here, the size of values of a type is not related to the well-formedness of said type</p>
</blockquote>
<p>is it, though? in my mental model, too big types are ill-formed, and hence <code>size_of</code> has every right to reject them.</p>
<p>I guess you'll complain that this is a rather non-compositional notion of well-formedness?</p>



<a name="217500641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217500641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217500641">(Nov 21 2020 at 12:51)</a>:</h4>
<p>My issue is that <code>[u16; usize::MAX]</code> is absolutely well formed</p>



<a name="217500686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217500686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217500686">(Nov 21 2020 at 12:52)</a>:</h4>
<p>you can use <code>&lt;[u16; usize::MAX] as Trait&gt;::Assoc</code> and similar things</p>



<a name="217502967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217502967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217502967">(Nov 21 2020 at 14:01)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217500641">said</a>:</p>
<blockquote>
<p>My issue is that <code>[u16; usize::MAX]</code> is absolutely well formed</p>
</blockquote>
<p>that is another possible definition of "well-formedness". then we have to live with the fact that there are well-formed types that cannot be translated to LLVM (it is my understanding that LLVM will choke at compiletime when we give it a type that is too big)</p>



<a name="217503016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217503016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217503016">(Nov 21 2020 at 14:02)</a>:</h4>
<p>and it's not just LLVM; once offsets within an allocation can get bigger than <code>isize::MAX</code> there'll also be trouble in CTFE</p>



<a name="217514979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217514979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217514979">(Nov 21 2020 at 19:24)</a>:</h4>
<p>yeah <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> while imo it makes sense to think of types like this in the same way as <code>!</code> supporting things like <code>*mut [u16; usize::MAX]</code> or whatever is probably not worth the effort, even if it were more consistent</p>



<a name="217515002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217515002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217515002">(Nov 21 2020 at 19:25)</a>:</h4>
<blockquote>
<p>there are well-formed types that cannot be translated to LLVM </p>
</blockquote>
<p>What about <code>enum Void</code>? How do we translate that to LLVM?</p>



<a name="217518373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217518373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217518373">(Nov 21 2020 at 20:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217515002">said</a>:</p>
<blockquote>
<blockquote>
<p>there are well-formed types that cannot be translated to LLVM </p>
</blockquote>
<p>What about <code>enum Void</code>? How do we translate that to LLVM?</p>
</blockquote>
<p>no idea but clearly we do</p>



<a name="217518376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217518376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217518376">(Nov 21 2020 at 20:49)</a>:</h4>
<p>are you suggesting we should translate too-big-to-be-real types the same way? hm...</p>



<a name="217518881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217518881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217518881">(Nov 21 2020 at 21:02)</a>:</h4>
<p>ideally <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span> realistically I am not too sure if it's worth the effort</p>



<a name="217547648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217547648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217547648">(Nov 22 2020 at 11:48)</a>:</h4>
<p>ooh... so since we know a value of type <code>[u16; usize::MAX]</code> can never exist, we can make the layout of it be the same layout as <code>!</code>, with all the effects that brings</p>



<a name="217547653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217547653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217547653">(Nov 22 2020 at 11:48)</a>:</h4>
<p>so.. <code>size_of</code> doesn't fail, but returns <code>0</code></p>



<a name="217547655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217547655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217547655">(Nov 22 2020 at 11:48)</a>:</h4>
<p>and any code following it is unreachable</p>



<a name="217547657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217547657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217547657">(Nov 22 2020 at 11:48)</a>:</h4>
<p>...</p>



<a name="217548226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217548226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217548226">(Nov 22 2020 at 12:04)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217547653">said</a>:</p>
<blockquote>
<p>so.. <code>size_of</code> doesn't fail, but returns <code>0</code></p>
</blockquote>
<p>no, size_of would return the large number. I thought.</p>



<a name="217548230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217548230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217548230">(Nov 22 2020 at 12:04)</a>:</h4>
<p>but maybe that's a problem in itself...</p>



<a name="217548238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217548238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217548238">(Nov 22 2020 at 12:04)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217547655">said</a>:</p>
<blockquote>
<p>and any code following it is unreachable</p>
</blockquote>
<p>why that? <code>size_of::&lt;!&gt;()</code> is perfectly reachable</p>



<a name="217548324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217548324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217548324">(Nov 22 2020 at 12:07)</a>:</h4>
<p>sorry, I mixed two concepts</p>



<a name="217548327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217548327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217548327">(Nov 22 2020 at 12:07)</a>:</h4>
<p><code>size_of::&lt;[u16; usize::MAX]&gt;()</code> cannot return any value, as <code>usize::MAX * 2</code> does not fit into a <code>usize</code></p>



<a name="217548389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217548389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217548389">(Nov 22 2020 at 12:09)</a>:</h4>
<p>but that's "fine", since there can be no values of type <code>[u16; usize::MAX]</code>. Basically <code>[0_u16; usize::MAX]</code> could be replaced by a runtime panic (+ emit a lint), making any code following it unreachable. At that point we can make the layout of <code>[u16; usize::MAX]</code> have the same layout as <code>!</code>, thus returning <code>0</code> for the size</p>



<a name="217548445"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217548445" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217548445">(Nov 22 2020 at 12:11)</a>:</h4>
<p>this makes <code>size_of::&lt;[u16; usize::MAX]&gt;()</code> "well defined" as <code>0</code>, though I worry how that interacts with <code>MaybeUninit&lt;[u16; usize::MAX]&gt;</code>, since someone could think this could be initialized element by element</p>



<a name="217548807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217548807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217548807">(Nov 22 2020 at 12:21)</a>:</h4>
<p><code>MaybeUninit&lt;[u16; usize::MAX]&gt;</code> still needs enough place to hold all <code>usize::MAX</code> elements right from the start</p>



<a name="217548846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217548846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217548846">(Nov 22 2020 at 12:22)</a>:</h4>
<p>so i don't think there is an issue with panicking there</p>



<a name="217548852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217548852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217548852">(Nov 22 2020 at 12:22)</a>:</h4>
<p><code>Option&lt;BigType&gt;</code> is a bit more weird, because one could imagine only needing the place for <code>BigType</code> once we have <code>Some</code></p>



<a name="217548872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217548872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217548872">(Nov 22 2020 at 12:23)</a>:</h4>
<p>but i personally did not think this way</p>



<a name="217549079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549079">(Nov 22 2020 at 12:28)</a>:</h4>
<p><code>Option&lt;BigType&gt;</code> would work automatically for my idea of making these types represented as <code>!</code>. It would become ZST and you could never have a <code>Some</code> of it</p>



<a name="217549089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549089">(Nov 22 2020 at 12:28)</a>:</h4>
<p>I'm not sure about <code>MaybeUninit</code> if we use the <code>!</code> layout, as it would now be zero sized.</p>



<a name="217549097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549097">(Nov 22 2020 at 12:29)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=5116d94942933bcc1e15cf677b5b6cde">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=5116d94942933bcc1e15cf677b5b6cde</a> works just fine, and users may start with partially initializing the elements</p>



<a name="217549183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549183">(Nov 22 2020 at 12:31)</a>:</h4>
<p>eddyb brought up something even worse just now. what if we initialize the array from the end to the beginning... then we have UB. The user may not have realized this, because their array length could have been generic</p>



<a name="217549295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549295">(Nov 22 2020 at 12:33)</a>:</h4>
<p>wait, won't the whole <code>MaybeUninit</code> become unrepresentable?</p>



<a name="217549301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549301">(Nov 22 2020 at 12:34)</a>:</h4>
<p>so if we propagate this outwards, we end up with <code>layout_of(MaybeUninit)</code> still returning an error</p>



<a name="217549341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549341">(Nov 22 2020 at 12:34)</a>:</h4>
<p>which we then only convert to a layout of size <code>0</code> for the whole type, whatever that means</p>



<a name="217549353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549353">(Nov 22 2020 at 12:34)</a>:</h4>
<p>at least that's how I imagine this</p>



<a name="217549600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549600">(Nov 22 2020 at 12:41)</a>:</h4>
<p>oh... so we keep the layout error, but we don't report it?</p>



<a name="217549731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549731">(Nov 22 2020 at 12:44)</a>:</h4>
<p>not sure, I expect <code>[(u8, [u16; usize::MAX]); 10]</code> to also be unrepresentable and not have size <code>10</code></p>



<a name="217549742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549742">(Nov 22 2020 at 12:44)</a>:</h4>
<p>well... in my system (which I now fully agree is not good and we should stop talking about it <span aria-label="grinning" class="emoji emoji-1f600" role="img" title="grinning">:grinning:</span>) it would have been <code>0</code></p>



<a name="217549750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549750">(Nov 22 2020 at 12:45)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217549742">said</a>:</p>
<blockquote>
<p>well... in my system (which I now fully agree is not good and we should stop talking about it :D) it would have been <code>0</code></p>
</blockquote>
<p>how?</p>



<a name="217549812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549812">(Nov 22 2020 at 12:46)</a>:</h4>
<p>you're right... I assumed <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=c3fdd5dae383852ec2c1092a5ba4b5d1">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=c3fdd5dae383852ec2c1092a5ba4b5d1</a> would be <code>0</code>, but.. partial initialization and such</p>



<a name="217549813"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549813" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549813">(Nov 22 2020 at 12:46)</a>:</h4>
<p>layout of <code>[(u8, [u16; usize::MAX]); 10]</code> uses layout of <code>(u8, [u16; usize::MAX])</code> which uses layout of <code>[u16; usize::MAX]</code> which returns 0 using your idea which means that <code>(u8, ?)</code> return 1 iiuc</p>



<a name="217549825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549825">(Nov 22 2020 at 12:46)</a>:</h4>
<p>as I said... ignore my system, it's broken in so many ways</p>



<a name="217549828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549828">(Nov 22 2020 at 12:46)</a>:</h4>
<p>let's go with yours, which I definitely find more reasonable</p>



<a name="217549854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549854">(Nov 22 2020 at 12:47)</a>:</h4>
<p>basically at the low level when creating locals and stuff, we treat <code>Err(..)</code> and <code>Ok(Uninhabited)</code> the same, except that the <code>Err</code> thing also inserts a <code>panic</code>?</p>



<a name="217549926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549926">(Nov 22 2020 at 12:49)</a>:</h4>
<p>ok... at that point the "treat the same" is irrelevant, and we just insert a <code>panic!</code> where the local would be <code>Err(SizeOverflow)</code></p>



<a name="217549932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549932">(Nov 22 2020 at 12:49)</a>:</h4>
<p>And maybe emit a lint</p>



<a name="217549984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549984">(Nov 22 2020 at 12:50)</a>:</h4>
<p>so... we're still stuck with the question around <code>size_of::&lt;[u16; usize::MAX]&gt;()</code></p>



<a name="217549985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217549985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217549985">(Nov 22 2020 at 12:50)</a>:</h4>
<p>we (likely) can't make that panic</p>



<a name="217555138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555138">(Nov 22 2020 at 14:59)</a>:</h4>
<p>Why can't that panic?</p>



<a name="217555147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555147">(Nov 22 2020 at 14:59)</a>:</h4>
<p>It seems reasonable to me that that should evaluate the same as <code>2 * usize::MAX</code></p>



<a name="217555199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555199">(Nov 22 2020 at 15:00)</a>:</h4>
<p>because people may use <code>size_of</code> in unsafe code rn</p>



<a name="217555204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555204">(Nov 22 2020 at 15:00)</a>:</h4>
<p>while expecting that it must not panic</p>



<a name="217555222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555222">(Nov 22 2020 at 15:01)</a>:</h4>
<p>so if we suddenly panic in <code>size_of</code> at least some existing snippets are suddenly unsound</p>



<a name="217555323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555323">(Nov 22 2020 at 15:03)</a>:</h4>
<p>is crashing the compiler an option?</p>



<a name="217555396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555396">(Nov 22 2020 at 15:04)</a>:</h4>
<p>like just say no if you have to monomorphize an impossible type</p>



<a name="217555489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555489">(Nov 22 2020 at 15:07)</a>:</h4>
<p>we are already doing that, but at least i don't want to</p>



<a name="217555505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555505">(Nov 22 2020 at 15:07)</a>:</h4>
<p>or much rather, the current state is a bit inconsistent imo</p>



<a name="217555557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555557">(Nov 22 2020 at 15:08)</a>:</h4>
<p>It seems the dilemma is: either types exist that don't fit in a <code>usize</code>, in which case the type of <code>mem::size_of</code> is a lie and making this visible will cause unsound code, or all types must fit in a <code>usize</code>, in which case the constraints on well formed types get really complicated and in particular are not closed under substitution, which breaks some pre-monomorphization checks</p>



<a name="217555569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555569">(Nov 22 2020 at 15:08)</a>:</h4>
<p>no type fits into a usize</p>



<a name="217555574"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555574" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555574">(Nov 22 2020 at 15:09)</a>:</h4>
<p>types do not have a size, instances of a type have a size</p>



<a name="217555585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555585">(Nov 22 2020 at 15:09)</a>:</h4>
<p>are we talking about <code>size_of_val</code> here? I thought it was <code>size_of</code></p>



<a name="217555633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555633">(Nov 22 2020 at 15:10)</a>:</h4>
<p>yeah, <code>size_of</code> returns the size of values of <code>T</code></p>



<a name="217555636"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555636" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555636">(Nov 22 2020 at 15:10)</a>:</h4>
<p>not the size of <code>T</code> itself</p>



<a name="217555639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555639">(Nov 22 2020 at 15:10)</a>:</h4>
<p>because <code>T</code> does not have a size</p>



<a name="217555647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555647">(Nov 22 2020 at 15:10)</a>:</h4>
<p>okay, that's an interesting distinction to make</p>



<a name="217555652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555652">(Nov 22 2020 at 15:10)</a>:</h4>
<p>it's a necessary one though</p>



<a name="217555661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555661">(Nov 22 2020 at 15:11)</a>:</h4>
<p>you can use <code>[u16; usize::MAX]</code> however you want until we try to compute its layout</p>



<a name="217555668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555668">(Nov 22 2020 at 15:11)</a>:</h4>
<p>at which point we currently always emit an error</p>



<a name="217555671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555671">(Nov 22 2020 at 15:12)</a>:</h4>
<p>So we can say that <code>T</code> is associated to a certain value, <code>size_of::&lt;T&gt;()</code>, which is a usize and satisfies the property that every element of the type has that size</p>



<a name="217555728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555728">(Nov 22 2020 at 15:12)</a>:</h4>
<p>in which case for uninhabited types we can pick whatever value we like</p>



<a name="217555753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555753">(Nov 22 2020 at 15:13)</a>:</h4>
<p>under this definition that's true <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span> <code>forall e. f(e) == n</code> is true for every <code>n</code> if <code>|e| == 0</code></p>



<a name="217555802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555802">(Nov 22 2020 at 15:14)</a>:</h4>
<p>If we say it is the minimum value, then uninhabited types get size 0</p>



<a name="217555810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217555810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217555810">(Nov 22 2020 at 15:14)</a>:</h4>
<p>my inner mathematician isn't so happy about <code>2 * usize::MAX = 0</code> though</p>



<a name="217556507"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217556507" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217556507">(Nov 22 2020 at 15:35)</a>:</h4>
<p>We could also add a requirement to the auto-implementation of <code>Sized</code> that <code>size_of</code> needs to successfully evaluate. This would be a breaking change, since <code>fn foo&lt;T&gt;() { }</code> can currently be invoked as <code>foo::&lt;[u16; usize::max_value()]&gt;()</code>, and with such a change this would give us a <code>[u16; usize::max_value()]: Sized</code> not satisfied error, requiring <code>foo</code> to have a <code>T: ?Sized</code> bound if it is supposed to be used with types too large to have values of</p>



<a name="217556553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217556553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217556553">(Nov 22 2020 at 15:36)</a>:</h4>
<p>Theoretically we can do this in an edition I guess?</p>



<a name="217556564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217556564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217556564">(Nov 22 2020 at 15:37)</a>:</h4>
<p>like have a new edition auto-generate some new <code>SizeOf</code> trait bounds everwhere where it generates <code>Sized</code> bounds</p>



<a name="217557182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217557182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217557182">(Nov 22 2020 at 15:53)</a>:</h4>
<blockquote>
<p>Basically [0_u16; usize::MAX] could be replaced by a runtime panic (+ emit a lint), making any code following it unreachable.</p>
</blockquote>
<p>I cannot parse this. <code>[0_u16; usize::MAX]</code>is a type, runtime panic an expression, you cannot replace a type by an expression.^^</p>



<a name="217557255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217557255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217557255">(Nov 22 2020 at 15:55)</a>:</h4>
<p><code>[0_u16; usize::MAX]</code> is a repeat expression of type <code>[u16; usize::MAX]</code></p>



<a name="217557258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217557258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217557258">(Nov 22 2020 at 15:55)</a>:</h4>
<p>oh sorry I misread</p>



<a name="217557266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217557266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217557266">(Nov 22 2020 at 15:55)</a>:</h4>
<p>TBH it seems silly to compile that into an always-panic, this should just not build...</p>



<a name="217557312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217557312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217557312">(Nov 22 2020 at 15:56)</a>:</h4>
<p>also what Oli mentioned above about generic code is even worse -- const-generic code may well assume that <code>[T; N]</code> has size <code>N*size_of::&lt;T&gt;()</code></p>



<a name="217557337"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217557337" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217557337">(Nov 22 2020 at 15:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217555574">said</a>:</p>
<blockquote>
<p>types do not have a size, instances of a type have a size</p>
</blockquote>
<p>(most) types do have a size, why are you saying this?^^</p>



<a name="217557340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217557340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Poliorcetics <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217557340">(Nov 22 2020 at 15:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217557312">said</a>:</p>
<blockquote>
<p>also what Oli mentioned above about generic code is even worse -- const-generic code may well assume that <code>[T; N]</code> has size <code>N*size_of::&lt;T&gt;()</code></p>
</blockquote>
<p>I certainly did until now, I think I assumed this in some school projects too</p>



<a name="217557401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217557401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217557401">(Nov 22 2020 at 15:58)</a>:</h4>
<blockquote>
<p>(most) types do have a size, why are you saying this?</p>
</blockquote>
<p>this is really pedantic, but what is the size of <code>u16</code>? Values of type <code>u16</code> have a size of 2 bytes but the type itself does not</p>



<a name="217557424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217557424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217557424">(Nov 22 2020 at 15:59)</a>:</h4>
<p>in general this issue did get <em>a bit</em> out of control regarding time spent when compared to how much we should be spending on this</p>
<p>i hope that it is at least enjoyable <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="217557760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217557760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217557760">(Nov 22 2020 at 16:07)</a>:</h4>
<p>maybe we need an "excessive pedantery and tangents" warning for threads so ppl know they can ignore them if they don't want to play that game <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="217558670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217558670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217558670">(Nov 22 2020 at 16:31)</a>:</h4>
<blockquote>
<p>this is really pedantic, but what is the size of u16? Values of type u16 have a size of 2 bytes but the type itself does not</p>
</blockquote>
<p>the size of u16 is 2</p>



<a name="217558711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217558711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217558711">(Nov 22 2020 at 16:32)</a>:</h4>
<p>being really pedantic I find the size of a type easier to define than the size of a value :D</p>



<a name="217558718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217558718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217558718">(Nov 22 2020 at 16:32)</a>:</h4>
<p>but FWIW, <a href="https://gitlab.mpi-sws.org/iris/lambda-rust">https://gitlab.mpi-sws.org/iris/lambda-rust</a> is as pedantic as it gets (formalized in Coq) and types have a size :)</p>



<a name="217558724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217558724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217558724">(Nov 22 2020 at 16:33)</a>:</h4>
<p>so I feel safe to say that types do have a size :D</p>



<a name="217558809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217558809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217558809">(Nov 22 2020 at 16:35)</a>:</h4>
<p>but of course there are many ways to define these things. just, if types dont have a size, we cannot define <code>size_of::&lt;T&gt;</code>, so, uh.^^<br>
in lambda-rust, values actually do have a size, and we define the size of a type as the size that all its values have (which in particular means all values of a type must have the same size, which is not necessarily given)</p>



<a name="217558818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217558818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217558818">(Nov 22 2020 at 16:35)</a>:</h4>
<p>however, with the framework I set up in <a href="https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/value-domain.md">https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/value-domain.md</a>, values dont have a size. types do.</p>



<a name="217558950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217558950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217558950">(Nov 22 2020 at 16:38)</a>:</h4>
<p>well, i think of <code>size_of::&lt;T&gt;()</code> to return <code>n</code> with <code>\forall x: T, size_of_val(&amp;x) == n</code>. This would allow <code>size_of::&lt;!&gt;()</code> and <code>size_of::&lt;[u16; usize::MAX]&gt;()</code> to return whatever we want</p>



<a name="217558973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217558973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217558973">(Nov 22 2020 at 16:39)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217558818">said</a>:</p>
<blockquote>
<p>however, with the framework I set up in <a href="https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/value-domain.md">https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/value-domain.md</a>, values dont have a size. types do.</p>
</blockquote>
<p>i think i've seen that document before but never really took too much time for it</p>



<a name="217559049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217559049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217559049">(Nov 22 2020 at 16:41)</a>:</h4>
<p>do you know how <code>lambda-rust</code> deals with <code>[u16; usize::MAX]</code>?</p>



<a name="217559070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217559070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217559070">(Nov 22 2020 at 16:41)</a>:</h4>
<p>does it use arbitrary precision integers for the size or are types without a size allowed?</p>



<a name="217577263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217577263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217577263">(Nov 22 2020 at 23:57)</a>:</h4>
<p>Hmm, I've sometimes said that <code>size_of::&lt;!&gt;()</code> is actually <code>-inf</code>, but saturates to <code>0</code>.  Maybe we could say that <code>size_of::&lt;[u32; usize::MAX - 1]()</code> also saturates, just to <code>usize::MAX</code>?</p>



<a name="217577790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217577790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217577790">(Nov 23 2020 at 00:08)</a>:</h4>
<p>That could work, although it complicates <code>offset_of</code> since now this can fail too. What is the offset of <code>u8</code> in <code>([u16; usize::MAX], u8)</code>?</p>



<a name="217578030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217578030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217578030">(Nov 23 2020 at 00:15)</a>:</h4>
<p>perhaps <code>usize::MAX</code>, since the understanding I had of this was essentially that if it actually saturates, then it's impossible to actually have an instant</p>



<a name="217578224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217578224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217578224">(Nov 23 2020 at 00:20)</a>:</h4>
<p>It still seems like a footgun to even consider the existence of these kinds of types. Unsafe code authors are <em>not</em> considering this case</p>



<a name="217578235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217578235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217578235">(Nov 23 2020 at 00:20)</a>:</h4>
<p>is there any practical application?</p>



<a name="217578502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217578502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Quy Nguyen <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217578502">(Nov 23 2020 at 00:26)</a>:</h4>
<p>Seems like the main one is not having to put const WF bounds for size_of.</p>



<a name="217578691"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217578691" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217578691">(Nov 23 2020 at 00:31)</a>:</h4>
<p>I mean, if we crash out eagerly then the type system can continue to pretend that types are unbounded in size and yet <code>size_of</code> returns a usize</p>



<a name="217578855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217578855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217578855">(Nov 23 2020 at 00:35)</a>:</h4>
<p>That seems the most similar to the usual way that arithmetic operations cause a panic on overflow: if you haven't considered this case then a crash is appropriate. In this case, the API design doesn't really let us fail nicely on these types, so if they ever arise we can throw a compile error</p>



<a name="217579556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217579556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217579556">(Nov 23 2020 at 00:54)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217577263">said</a>:</p>
<blockquote>
<p>Hmm, I've sometimes said that <code>size_of::&lt;!&gt;()</code> is actually <code>-inf</code>, but saturates to <code>0</code>.  Maybe we could say that <code>size_of::&lt;[u32; usize::MAX - 1]()</code> also saturates, just to <code>usize::MAX</code>?</p>
</blockquote>
<p>Assigning <code>!</code> any size seems misleading to me. It doesn't have a size (negative infinity or otherwise).</p>



<a name="217580300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217580300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217580300">(Nov 23 2020 at 01:13)</a>:</h4>
<blockquote>
<p>It still seems like a footgun to even consider the existence of these kinds of types. Unsafe code authors are not considering this case</p>
</blockquote>
<p>Yeah, as someone who writes plenty of unsafe code, having to consider this (which seems more likely once min_const_generics come around) seems like a absolute headache that I wouldn't have considered at all before now.</p>



<a name="217580398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217580398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217580398">(Nov 23 2020 at 01:15)</a>:</h4>
<p>IMO ideally size_of on such a type would just produce an error, honestly. The size can't be represented as a usize, so this seems totally reasonable and the best way to adding a footgun</p>



<a name="217594972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217594972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217594972">(Nov 23 2020 at 07:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="209168">Thom Chiovoloni</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217580398">said</a>:</p>
<blockquote>
<p>IMO ideally size_of on such a type would just produce an error, honestly. The size can't be represented as a usize, so this seems totally reasonable and the best way to adding a footgun</p>
</blockquote>
<p>it does report an error, but that fact is not represented in the generic parameters of a function, so <code>size_of::&lt;T&gt;()</code> inside a generic function can fail arbitrarily while monomorphizing the function. Ideally we'd error because some generic bounds on the function aren't satisfied</p>



<a name="217604855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217604855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217604855">(Nov 23 2020 at 09:26)</a>:</h4>
<p>I don't see the problem with that. This is a monomorphization time problem</p>



<a name="217604917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217604917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217604917">(Nov 23 2020 at 09:27)</a>:</h4>
<p>This is like, generically you can say that <code>n + 1</code> is a number whenever <code>n</code> is but if you use that constructor enough times bad things will happen</p>



<a name="217605000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217605000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217605000">(Nov 23 2020 at 09:28)</a>:</h4>
<p>and you can't know in advance how deeply things will nest until monomorphization time</p>



<a name="217605054"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217605054" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217605054">(Nov 23 2020 at 09:28)</a>:</h4>
<p>Monomorphization time errors are bad for usability. There is a reason we don't take the C++ approach, but instead use trait bounds.</p>



<a name="217605330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217605330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217605330">(Nov 23 2020 at 09:31)</a>:</h4>
<p>I understand that, but I think <em>this particular problem</em> doesn't make any sense with trait bounds</p>



<a name="217683922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217683922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217683922">(Nov 23 2020 at 21:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217559049">said</a>:</p>
<blockquote>
<p>do you know how <code>lambda-rust</code> deals with <code>[u16; usize::MAX]</code>?</p>
</blockquote>
<p>we use natural numbers for everything. so there's no upper bound.</p>



<a name="217683999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217683999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217683999">(Nov 23 2020 at 21:18)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217577263">said</a>:</p>
<blockquote>
<p>Hmm, I've sometimes said that <code>size_of::&lt;!&gt;()</code> is actually <code>-inf</code>, but saturates to <code>0</code>.  Maybe we could say that <code>size_of::&lt;[u32; usize::MAX - 1]()</code> also saturates, just to <code>usize::MAX</code>?</p>
</blockquote>
<p>the way things currently stand, it should saturate to <code>isize::MAX as usize</code>, actually...</p>



<a name="217684062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217684062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217684062">(Nov 23 2020 at 21:19)</a>:</h4>
<blockquote>
<p>Hmm, I've sometimes said that size_of::&lt;!&gt;() is actually -inf, but saturates to 0.</p>
</blockquote>
<p>FWIW, in lambdaRust (and also with <span class="user-mention" data-user-id="216206">@lcnr</span>'s derived notion of the size of a type), <code>!</code> can have <em>any possible size</em>. we can literally pick whatever we want and it is correct (as <span class="user-mention" data-user-id="216206">@lcnr</span> already said above)</p>



<a name="217684220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217684220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217684220">(Nov 23 2020 at 21:20)</a>:</h4>
<p><span class="user-mention silent" data-user-id="121053">varkor</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217579556">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217577263">said</a>:</p>
<blockquote>
<p>Hmm, I've sometimes said that <code>size_of::&lt;!&gt;()</code> is actually <code>-inf</code>, but saturates to <code>0</code>.  Maybe we could say that <code>size_of::&lt;[u32; usize::MAX - 1]()</code> also saturates, just to <code>usize::MAX</code>?</p>
</blockquote>
<p>Assigning <code>!</code> any size seems misleading to me. It doesn't have a size (negative infinity or otherwise).</p>
</blockquote>
<p>that definitely depends on your definition.^^ since <code>!: Sized</code>, I think saying it doesnt have a size makes no sense. And lambda-rust provides a concrete formal framework in which <code>!</code> can have any possible size, so <code>0</code> seems like the most reasonable choice. (lambda-rust does not cover all of Rust, in particular it does not cover DST, but I see no issue generalizing this approach.)</p>



<a name="217684309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217684309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217684309">(Nov 23 2020 at 21:21)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217594972">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="209168">Thom Chiovoloni</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217580398">said</a>:</p>
<blockquote>
<p>IMO ideally size_of on such a type would just produce an error, honestly. The size can't be represented as a usize, so this seems totally reasonable and the best way to adding a footgun</p>
</blockquote>
<p>it does report an error, but that fact is not represented in the generic parameters of a function, so <code>size_of::&lt;T&gt;()</code> inside a generic function can fail arbitrarily while monomorphizing the function. Ideally we'd error because some generic bounds on the function aren't satisfied</p>
</blockquote>
<p>to be clear, this fails during monomorphizaion not just specifically for <code>size_of</code>, right? if the function uses <code>T</code> in any way where its size could possibly matter, monomorphization fails.</p>



<a name="217684695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217684695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217684695">(Nov 23 2020 at 21:25)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> </p>
<blockquote>
<p>well, i think of size_of::&lt;T&gt;() to return n with \forall x: T, size_of_val(&amp;x) == n. </p>
</blockquote>
<p>So types <em>do</em> have a size after all :) it is the <code>n</code> such that <code>\forall x: T, size_of_val(&amp;x) == n</code>. That's exactly what lambda-rust does. The size is a <em>defined</em> notion, nothing "primitive", but that doesn't mean that it doesn't <em>exist</em>. Almost everything in math is a defined notion, after all.</p>



<a name="217685768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217685768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217685768">(Nov 23 2020 at 21:36)</a>:</h4>
<p>yeah, and i think defining <code>n</code> such that <code>\forall x: T, size_of_val(&amp;x) == n</code> to be the "size" of <code>T</code> is not a helpful notion <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="217685843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217685843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217685843">(Nov 23 2020 at 21:37)</a>:</h4>
<p>it's a used one though :_</p>



<a name="217703508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217703508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Quy Nguyen <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217703508">(Nov 24 2020 at 00:58)</a>:</h4>
<p>It looks we already fail post-monomorphization on the case though, so it shouldn't be too difficult to just accept it as a post monomorphization error no?</p>
<p>Aside: monomorphization is terrible to spell</p>



<a name="217735311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/217735311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#217735311">(Nov 24 2020 at 10:30)</a>:</h4>
<p>yea, we don't have to change anything to keep the post-monomorphization error. What this thread is about is brainstorming whether we can eliminate that post-monomorphization error</p>



<a name="218119751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/mem%3A%3Asize_of%3A%20do%20not%20error%20if%20layout%20computations%20fail/near/218119751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail.html#218119751">(Nov 27 2020 at 18:42)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/213817-t-lang/topic/mem.3A.3Asize_of.3A.20do.20not.20error.20if.20layout.20computations.20fail/near/217685843">said</a>:</p>
<blockquote>
<p>it's a used one though :_</p>
</blockquote>
<p><a href="#narrow/stream/213817-t-lang/topic/Do.20types.20have.20a.20size.3F">Continuing here</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>